
var RootUrl = "";

function removePanel() {
    var tab = $('#tabs').tabs('getSelected');
    if (tab) {
        var index = $('#tabs').tabs('getTabIndex', tab);
        $('#tabs').tabs('close', index);
    }
}


function tabClose() {
    /*双击关闭TAB选项卡*/
    $(".tabs-inner").dblclick(function () {
        var subtitle = $(this).children(".tabs-closable").text();
        $('#tabs').tabs('close', subtitle);
    })
    /*为选项卡绑定右键*/
    $(".tabs-inner").bind('contextmenu', function (e) {
        $('#mm').menu('show', {
            left: e.pageX,
            top: e.pageY
        });

        var subtitle = $(this).children(".tabs-closable").text();

        $('#mm').data("currtab", subtitle);
        $('#tabs').tabs('select', subtitle);
        return false;
    });
}

//绑定右键菜单事件
function tabCloseEven() {
    //刷新
    $('#mm-tabupdate').click(function () {
        var currTab = $('#tabs').tabs('getSelected');
        var url = $(currTab.panel('options').content).attr('src');
        if (url != undefined && currTab.panel('options').title != '首页') {
            $('#tabs').tabs('update', {
                tab: currTab,
                options: {
                    content: createFrame(url)
                }
            })
        }
    })
    //关闭当前
    $('#mm-tabclose').click(function () {
        var currtab_title = $('#mm').data("currtab");
        $('#tabs').tabs('close', currtab_title);
    })
    //全部关闭
    $('#mm-tabcloseall').click(function () {
        $('.tabs-inner span').each(function (i, n) {
            var t = $(n).text();
            if (t != '首页') {
                $('#tabs').tabs('close', t);
            }
        });
    });
    //关闭除当前之外的TAB
    $('#mm-tabcloseother').click(function () {
        var prevall = $('.tabs-selected').prevAll();
        var nextall = $('.tabs-selected').nextAll();
        if (prevall.length > 0) {
            prevall.each(function (i, n) {
                var t = $('a:eq(0) span', $(n)).text();
                if (t != '首页') {
                    $('#tabs').tabs('close', t);
                }
            });
        }
        if (nextall.length > 0) {
            nextall.each(function (i, n) {
                var t = $('a:eq(0) span', $(n)).text();
                if (t != '首页') {
                    $('#tabs').tabs('close', t);
                }
            });
        }
        return false;
    });
    //关闭当前右侧的TAB
    $('#mm-tabcloseright').click(function () {
        var nextall = $('.tabs-selected').nextAll();
        if (nextall.length == 0) {
            //msgShow('系统提示','后边没有啦~~','error');
            alert('后边没有啦~~');
            return false;
        }
        nextall.each(function (i, n) {
            var t = $('a:eq(0) span', $(n)).text();
            $('#tabs').tabs('close', t);
        });
        return false;
    });
    //关闭当前左侧的TAB
    $('#mm-tabcloseleft').click(function () {
        var prevall = $('.tabs-selected').prevAll();
        if (prevall.length == 0) {
            alert('到头了，前边没有啦~~');
            return false;
        }
        prevall.each(function (i, n) {
            var t = $('a:eq(0) span', $(n)).text();
            $('#tabs').tabs('close', t);
        });
        return false;
    });

    //退出
    $("#mm-exit").click(function () {
        $('#mm').menu('hide');
    })
}
function setCookie(name, value) {//两个参数，一个是cookie的名子，一个是值
    var Days = 30; //此 cookie 将被保存 30 天
    var exp = new Date();    //new Date("December 31, 9998");
    exp.setTime(exp.getTime() + Days * 24 * 60 * 60 * 1000);
    document.cookie = name + "=" + escape(value) + ";expires=" + exp.toGMTString();
}

function getCookie(name) {//取cookies函数        
    var arr = document.cookie.match(new RegExp("(^| )" + name + "=([^;]*)(;|$)"));
    if (arr != null) return unescape(arr[2]); return null;
}

function ShowException(data) {
    if (typeof (data) == 'object') {
        $('#PopWindowContet').html(data.responseText);
    }
    else {
        $('#PopWindowContet').html(data);
    }
    $('#PopWindow').window({
        width: 160,title:'',
        height: 6,
        modal: true
    });
    $('#PopWindow').window('open');
}
function addPanelAndIcon(id, title, _iconCls, src) {
    var panelHeight = $('#tabs').tabs('getTab', 0).height() - 25;
    var panelwidth = $('#tabs').tabs('getTab', 0).width() - 25;
    $('#tabs').tabs('add', {
        //iconCls: _iconCls,
        title: title,
        content: '<iframe scrolling="yes" frameborder="0"  src="' + src + '" style="margin: 10px;width:' + panelwidth + 'px;height:' + panelHeight + 'px;"></iframe>',
        closable: true
    });
    tabClose(); 
}

function addPanel(id, title, src) {
    var panelHeight = $('#tabs').tabs('getTab', 0).height() - 25;
    var panelwidth = $('#tabs').tabs('getTab', 0).width() - 25;
    $('#tabs').tabs('add', {
        //iconCls: 'icon-' + id,
        title: title,
        content: '<iframe scrolling="yes" frameborder="0"  src="' + src + '" style="margin: 10px;width:' + panelwidth + 'px;height:' + panelHeight + 'px;"></iframe>',
        closable: true
    });
    tabClose(); 
}
function fun_baseGoUrl(url) {
    window.location.href = url;
}
function ShowPopWindow(_title, _url) {
    var _width = $(window).width() - 200;
    var _height = $(window).height() - 150;
    $('#PopWindow').dialog({
        title: _title,
        iconCls: 'icon-edit'  ,
        width: _width,
        height: _height,
        closed: false,
        cache: false,
        //href: _url,
        content: '<iframe scrolling="no" frameborder="0"  src="' + _url + '" style="width:100%;height:98%"; overflow:hidden"></iframe>',
        modal: true
    });
}

function ClosePopWindow() {
    $('#PopWindow').dialog({
        closed: true,
        content: ' a'
    });

}
function fun_ShowPopWindow(id, title, text) {
    $('#PopWindow').dialog({
        title: title,
        iconCls: 'icon-edit',
        width: 520,
        height: 200,
        closed: false,
        cache: false,
        content: text,
        modal: true
    });
}
function fun_ShowPopWindowUrl(id, title, url, w_width, w_height) {  
    $('#PopWindow').dialog({
        title: title,
        iconCls: 'icon-edit'  ,
        width: w_width == undefined ? 720 : w_width, 
        height: w_height == undefined ? $(window).height()*0.8 : w_height,
        closed: false,
        cache: false,
        content: '<iframe scrolling="yes" frameborder="0"  src="' + url + '" style="width:100%;height:98%;overflow:hidden"></iframe>',
        modal: true
    });
}
function InintChart(divid, type, title, memo, ytitle) {
    $.ajax({
        async: true,
        type: "get",
        url: "/AppAPI/" + type,
        dataType: 'json',
        error: function (rq, textStatus, errorThrown) {
            $.messager.alert("错误", rq.statusText + '(' + rq.status + '):' + rq.responseText, "error");
        },
        success: function (result) { 
            var date = new Date();
            var cate = [];
            date.setDate(date.getDate() - 7);
            for (i = 0; i < 7; i++) {
                date.setDate(date.getDate() + 1);
                cate.push((date.getMonth() + 1) + '月' + date.getDate() + '日');
            }

            $(divid).highcharts({
                chart: {
                    type: 'spline'
                },
                title: {
                    text: title
                },
                subtitle: {
                    text: memo
                },
                xAxis: {
                    categories: ['一月', '二月', '三月', '四月', '五月', '六月',
                                 '七月', '八月', '九月', '十月', '十一月', '十二月']
                },
                yAxis: {
                    title: {
                        text: ytitle
                    },
                    labels: {
                        formatter: function () {
                            return this.value + '°';
                        }
                    }
                },
                tooltip: {
                    crosshairs: true,
                    shared: true
                },
                plotOptions: {
                    spline: {
                        marker: {
                            radius: 4,
                            lineColor: '#666666',
                            lineWidth: 1
                        }
                    }
                },
                series: [{
                    name: '东京',
                    marker: {
                        symbol: 'square'
                    },
                    data: [7.0, 6.9, 9.5, 14.5, 18.2, 21.5, 25.2, {
                        y: 26.5,
                        marker: {
                            symbol: 'url(https://www.highcharts.com/demo/gfx/sun.png)'
                        }
                    }, 23.3, 18.3, 13.9, 9.6]
                }, {
                    name: '伦敦',
                    marker: {
                        symbol: 'diamond'
                    },
                    data: [{
                        y: 3.9,
                        marker: {
                            symbol: 'url(https://www.highcharts.com/demo/gfx/snow.png)'
                        }
                    }, 4.2, 5.7, 8.5, 11.9, 15.2, 17.0, 16.6, 14.2, 10.3, 6.6, 4.8]
                }]
            }); 

            $("#chart_add text").each(function (i) { 
                if ($(this).html().indexOf ('Highcharts.com')>=0) {
                    $(this).css("display","none");
                }
            });
        }
    });
} 

function initQukNav() { 
    $("#QukNav li   ").each(function (i) {
        this.onclick = function () {
            var liobj = $(this) ;
            if (liobj.attr('URLLINK') == undefined) return;
            id = liobj.attr('Type_ID');
            text = liobj.children('img').attr("title");
            url = RootUrl + liobj.attr('URLLINK');
            var width = 720;
            var height = 720;
            if (liobj.attr('WINDOWWIDTH') != undefined) {
                width=liobj.attr('WINDOWWIDTH');
            }
            if (liobj.attr('WINDOWHEIGHT') != undefined) {
                height = liobj.attr('WINDOWHEIGHT');
            }
            if (liobj.attr('OPENPANEL') != undefined) {
                addPanel(id, text, url)
                return;
            }
            else if (liobj.attr('RDURL') != undefined) {
                fun_baseGoUrl(url);
                return;
            }
            else if (liobj.attr('OPENWINDOW') != undefined) {
                fun_ShowPopWindowUrl(id, text, url, width, height);
                return;
            }
            else if (liobj.attr('URLLINK') != undefined) {
                fun_ShowPopWindowUrl(id, text, url, width, height);
                return;
            }
            else {
                html += 'alert(\'为定义按钮打开方式！\')';
            }
        }

    });
}
$(function () {
    var cssstr = getQueryStringByName('theme'); 
    tabCloseEven(); 
    initQukNav(); //初始化快捷
    $('#tabs').tabs({
        // tabPosition:'left' ,       
        border: false
    }); 
    
    //InintChart('#chart_add', 'CHARTDAYADD', '新增操作次数', '记录管理员操作新增次数', '新增记录数 ( 次 )');
    //InintChart('#chart_update', 'CHARTDAYAUPDATE', '更新操作次数', '记录管理员操作更新数据次数', '更新记录数 ( 次 )');
    //InintChart('#chart_del', 'CHARTDAYDEL', '删除操作次数', '记录管理员操作删除数据次数', '删除数据记录数 ( 次 )');
    //InintChart('#chart_list', 'CHARTDAYLIST', '查看列表操作次数', '记录管理员查看列表的次数', '查看列表记录数 ( 次 )');

    $('#londing').window('close');
});

//alert($('#tabs').);